using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Collections;
using System.Xml;

namespace Customs.Components.SXXK.ThanhKhoan
{
    public class HoSoThanhKhoan
    {
        public static DataSet GetHoSoThanhKhoan(string maHaiQuan, string maDoanhNghiep)
        {
            string connectionString = ConnectionManager.GetConnectionString("SXXK", maHaiQuan);
            string query = "SELECT * FROM DLANTHANHLY WHERE MA_HQ = @MA_HQ AND MA_DV = @MA_DV ";

            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@Ma_HQ", SqlDbType.Char);
            parameters[0].Size = 6;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@Ma_DV", SqlDbType.VarChar);
            parameters[1].Size = 14;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maDoanhNghiep;            

            DataSet ds= SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query, parameters);
            return ds;
        }

        public static DataSet GetHoSoThanhKhoanOfLanThanhLy(string maHaiQuan, string maDoanhNghiep, int lanthanhly)
        {
            string connectionString = ConnectionManager.GetConnectionString("SXXK", maHaiQuan);
            string query = "SELECT * FROM DLANTHANHLY WHERE MA_HQ = @MA_HQ AND MA_DV = @MA_DV AND LAN_TL=@LAN_TL";

            SqlParameter[] parameters = new SqlParameter[3];

            parameters[0] = new SqlParameter("@Ma_HQ", SqlDbType.Char);
            parameters[0].Size = 6;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@Ma_DV", SqlDbType.VarChar);
            parameters[1].Size = 14;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maDoanhNghiep;

            parameters[2] = new SqlParameter("@LAN_TL", SqlDbType.Int);            
            parameters[2].Direction = ParameterDirection.Input;
            parameters[2].Value = lanthanhly;

            DataSet ds = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query, parameters);
            return ds;
        }
        /// <summary>
        /// Lay tat ca thong tin cua cac ho so thanh khoan
        /// </summary>
        /// <param name="maHaiQuan"></param>
        /// <param name="maDoanhNghiep"></param>
        /// <returns></returns>
        public static string[] GetHoSoThanhKhoanALL(string maHaiQuan, string maDoanhNghiep)
        {
            ArrayList list = new ArrayList();
            DataSet ds = GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count==0)
                return null;
            list.Add(ds.GetXmlSchema());
            list.Add(ds.GetXml());

            ds = DanhSachTKNhap.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachTKXuat.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds =DanhSachNPLChuaThanhLy.GetHoSoThanhKhoan(maHaiQuan,maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLHuy.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }


            ds = DanhSachNPLNopThue.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLTaiXuat.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLTamNopThue.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLXuatGiaCong.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLXuatNKD.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLTuCungUng.GetHoSoThanhKhoan(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }  

            
                string[] kq = new string[list.Count];
                for (int i = 0; i < list.Count; ++i)
                    kq[i] = list[i].ToString();
                return kq;
        }
        /// <summary>
        /// Lay ho so thanh khoan cua mot lan thanh khoan
        /// </summary>
        /// <param name="maHaiQuan"></param>
        /// <param name="maDoanhNghiep"></param>
        /// <param name="lanthanhly"></param>
        /// <returns></returns>
        public static string[] GetHoSoThanhKhoanOfLanThanhLyALL(string maHaiQuan, string maDoanhNghiep,int lanthanhly)
        {
            ArrayList list = new ArrayList();
            DataSet ds = GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep, lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
                return null;
            list.Add(ds.GetXmlSchema());
            list.Add(ds.GetXml());

            ds = DanhSachTKNhap.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachTKXuat.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLChuaThanhLy.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLHuy.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }


            ds = DanhSachNPLNopThue.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLTaiXuat.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLTamNopThue.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLXuatGiaCong.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLXuatNKD.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }

            ds = DanhSachNPLTuCungUng.GetHoSoThanhKhoanOfLanThanhLy(maHaiQuan, maDoanhNghiep,lanthanhly);
            if (ds.Tables[0].Rows.Count == 0)
            {
                list.Add("");
                list.Add("");
            }
            else
            {
                list.Add(ds.GetXmlSchema());
                list.Add(ds.GetXml());
            }  

            string[] kq = new string[list.Count];
            for (int i = 0; i < list.Count; ++i)
                kq[i] = list[i].ToString();
            return kq;
        }
        /// <summary>
        /// Lay thong tin ton ve luong va thue cua mot
        /// laan thanh ly
        /// </summary>
        /// <param name="maHaiQuan"></param>
        /// <param name="maDoanhNghiep"></param>
        /// <param name="lanthanhly"></param>
        /// <returns></returns>
        public static string[] GetThongTinTonNPLOfLanThanhLy(string maHaiQuan, string maDoanhNghiep, int lanthanhly)
        {
            ArrayList list = new ArrayList();
            DataSet ds = new DataSet();         
            ds = ThongTinTonNPLTaiXuat.GetTonNPLTaiXuatOfLanThanhLy(maHaiQuan, maDoanhNghiep, lanthanhly);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            ds = ThongTinTonNPLXuat.GetTonNPLXuatOfLanThanhLy(maHaiQuan, maDoanhNghiep, lanthanhly);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            ds = ThongTinTonNPLNhap.GetTonNPLNhapOfLanThanhLy(maHaiQuan, maDoanhNghiep, lanthanhly);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            ds = ThongTinTonNPLNhap.GetTonThueNPLNhapOfLanThanhLy(maHaiQuan, maDoanhNghiep, lanthanhly);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            string[] kq = new string[list.Count];
            for (int i = 0; i < list.Count; ++i)
                kq[i] = list[i].ToString();
            return kq;
        }
        /// <summary>
        /// Lay thong tin ton cua tat ca cac ho so thanh ly
        /// </summary>
        /// <param name="maHaiQuan"></param>
        /// <param name="maDoanhNghiep"></param>
        /// <param name="lanthanhly"></param>
        /// <returns></returns>
        public static string[] GetThongTinTonNPL(string maHaiQuan, string maDoanhNghiep)
        {
            ArrayList list = new ArrayList();
            DataSet ds = new DataSet();           
            ds = ThongTinTonNPLNhap.GetTonNPLNhap(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            ds = ThongTinTonNPLNhap.GetTonThueNPLNhap(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            ds = ThongTinTonNPLTaiXuat.GetTonNPLTaiXuat(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            ds = ThongTinTonNPLXuat.GetTonNPLXuat(maHaiQuan, maDoanhNghiep);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string st = ds.GetXml();
                list.Add(st);
                st = ds.GetXmlSchema();
                list.Add(st);
            }
            else
            {
                list.Add("");
                list.Add("");
            }
            string[] kq = new string[list.Count];
            for (int i = 0; i < list.Count; ++i)
                kq[i] = list[i].ToString();
            return kq;
        }
    }
}
